package com.ruoyi.project.business.tmppost.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.project.business.tmppost.entity.TmpPost;
import com.ruoyi.project.business.tmppost.mapper.TmpPostMapper;
import com.ruoyi.project.business.tmppost.request.AddTmpPostRequest;
import com.ruoyi.project.business.tmppost.request.ListTmpPostRequest;
import com.ruoyi.project.business.tmppost.response.TmpPostResponse;
import com.ruoyi.project.business.tmppost.service.ITmpPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 临工岗位Service业务层处理
 * 
 * @author ${author}
 * @date 2024-04-01
 */
@Service
public class TmpPostServiceImpl implements ITmpPostService {
    @Autowired
    private TmpPostMapper tmpPostMapper;

    /**
     * 查询临工岗位
     * 
     * @return 临工岗位
     */
    @Override
    public TmpPost selectTmpPostById(Long id) {
        return tmpPostMapper.selectTmpPostById(id);
    }

    /**
     * 查询临工岗位列表
     * 
     * @return 临工岗位
     */
    @Override
    public List<TmpPostResponse> selectTmpPostList(ListTmpPostRequest request, Long tenantId) {
        // TODO request to  param
        TmpPost param = BeanUtils.copy(request, TmpPost.class);
        param.setTenantId(tenantId);
        List<TmpPost> entitis = tmpPostMapper.selectTmpPostList(param);
        List<TmpPostResponse> resList = BeanUtils.copyList(entitis, TmpPostResponse.class);
        return resList;
    }

    /**
     * 新增临工岗位
     * 
     * @return 结果
     */
    @Override
    public int insertTmpPost(AddTmpPostRequest request, Long operatorId, Long tenantId) {
        TmpPost entity = BeanUtils.copy(request, TmpPost.class);
        entity.setTenantId(tenantId);
        entity.setCreator(operatorId);
        entity.setDeleted(Boolean.FALSE);
        entity.setCreateTime(DateUtils.getNowDate());
        return tmpPostMapper.insertTmpPost(entity);
    }

    /**
     * 修改临工岗位
     * 
     * @return 结果
     */
    @Override
    public int updateTmpPost(TmpPost entity, Long operatorId, Long tenantId) {
        entity.setUpdateTime(DateUtils.getNowDate());
        entity.setTenantId(tenantId);
        entity.setUpdater(operatorId);
        return tmpPostMapper.updateTmpPost(entity);
    }

    /**
     * 批量删除临工岗位
     * 
     * @return 结果
     */
    @Override
    public int deleteTmpPostByIds(Long[] ids, Long operatorId, Long tenantId) {
        return tmpPostMapper.deleteTmpPostByIds(ids);
    }

    /**
     * 删除临工岗位信息
     * 
     * @return 结果
     */
    @Override
    public int deleteTmpPostById(Long id, Long operatorId, Long tenantId) {
        return tmpPostMapper.deleteTmpPostById(id);
    }
}
